<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link href="../../layui/css/layui.css" rel="stylesheet">
    <script src="../../layui/layui.js"></script>
</head>
<body>
<style>
    .layui-form {
        margin-top: 30px;
    }

    .demo-login-container {
        width: 320px;
        margin: 21px auto 0;
    }

    .demo-login-other .layui-icon {
        position: relative;
        display: inline-block;
        margin: 0 2px;
        top: 2px;
        font-size: 26px;
    }
</style>
<form class="layui-form"lay-filter="editForm">
    <div class="demo-login-container">

        <div class="layui-form-item">
            <div class="layui-input-wrap">
                <input type="hidden" name="id"/>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-wrap">
                <input type="text" name="publisher" value="" lay-verify="required" placeholder="发布人"
                       lay-reqtext="请填写发布人" autocomplete="off" class="layui-input" lay-affix="clear">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <div class="layui-input-wrap">
                <textarea placeholder="请输入活动内容" name="content" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item" id="login" >
            <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="editActive" >更新活动</button>
        </div>
    </div>
</form>

<script>
    layui.use(function () {
        let form = layui.form;
        let layer = layui.layer;
        let $ = layui.$;


        let active = JSON.parse(sessionStorage.getItem("active"));
        sessionStorage.removeItem("active")
        form.val('editForm',active)
        form.render();

        // 提交事件
        form.on('submit(editActive)', function (data) {
            let formData = data.field; // 获取表单字段值
            // 此处可执行 Ajax 等操作
            $.ajax({
                url:'/sport/active/edit',
                data:formData,
                type:'post',
                dataType:'json',
                success:function (res){
                    if (res.code==0){
                        layer.msg(res.msg,{icon:1},function (){
                            // 关闭弹出层
                            let index = parent.layer.getFrameIndex(window.name); // 先得到当前 iframe 层的索引
                            parent.layer.close(index);
                        })
                    }else {
                        layer.msg(res.msg,{icon:2})
                    }
                }
            })
            // 再执行关闭
            return false; // 阻止默认 form 跳转
        });

    });
</script>
</body>
</html>